/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * \file
 * \brief Protocol encoder/decoder header for the ObjectDB protocol.
 * \author Antti Maula <antti.maula@tkk.fi>
 *
 * $Id: ObjectDBData.hpp,v 1.3 2009-09-01 12:56:27 amaula Exp $
 * 
 */
#ifndef _MACI_OBJECTDBDATA_HPP_
#define _MACI_OBJECTDBDATA_HPP_
#include "ObjectDBTypes.hpp"
#include "MaCIData.hpp"
#include "common/timestamp.hpp"
#include <vector>
#include <map>

namespace gim {
  namespace binbag{class CBinBag;}
}

namespace MaCI {
  namespace ObjectDB {

    /** RealObject information group. All four fields describe a
     *  Information entry.
     *
     * \note This object uses std::strings, which will duplicate the
     * container data instead of pointing directly. This approach was
     * selected due to dynamic nature of the contained data. Also,
     * this interface is more or less 'batch-driven', hence a few
     * extra data copies against usability weights less.
     */
    struct SRealObjectInformation {
      SRealObjectInformation(const unsigned int aId = 0,
                             const std::string &aName = "",
                             const std::string &aType = "",
                             const std::string &aDescription = "") 
        : id(aId),
          name(aName),
          type(aType),
          description(aDescription) {}
      unsigned int id;
      std::string name;
      std::string type;
      std::string description;
    };



#if 0 // Structure for easier use.
    struct SRealObjectInformation {
      SRealObjectInformation(const SRealObjectPtrInformation &aSrc)
        : id(aSrc.id),
          name(aSrc.name),
          type(aSrc.type),
          description(aSrc.description) {}
      unsigned int id;
      std::string name;
      std::string type;
      std::string description;
    };
#endif


    /** ObjectDB protocol parser.
     *
     * This class contains the methods for decoding/encoding a 
     * ObjectDB message.
     */
    class CObjectDBData : public CMaCIData
    {
    public:
      CObjectDBData();
      ~CObjectDBData();

      // Copy constructor.
      CObjectDBData(const CObjectDBData &);

      // Assignment operator.
      CObjectDBData &operator=(const CObjectDBData &);

      // Interface for moving data around
      bool DecodeFrom(gim::binbag::CBinBag *aBinBag);
      void Reset();
      void Print(const int level) const;


      /** Set timestamp element.
       * 
       */
      bool SetTimestamp(const Common::TTimestamp &aStamp);


      /** Set command element.
       * This function stores a element of type TCommand.
       *
       * @return                'true' if element was succesfully added,
       *                        'false' if element already exists.
       */
      bool SetCommand(const TCommand &aCmd);


      /** Add a new RealObjectInformation group of elements.
       * 
       * Each call consists of 4 added elements (if strings are
       * non-empty).
       *
       */
      bool AddRealObjectInformation(const SRealObjectInformation &aInfo);


      /** Get pointer to TTimestamp element.
       * 
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      const MaCI::Common::TTimestamp *GetTimestamp(void) const;
      

      /** Get pointer to TCommand element.
       *
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      const TCommand *GetCommand(void) const;

      const TDBObjectHandleArray *GetDBObjectHandleArray(void) const;

    private:
      const Common::TTimestamp *iTimestampPtr; ///< Pointer to timestamp if exists
      const TCommand *iCommandPtr;             ///< Pointer to command if any.
      
      std::vector<SRealObjectInformation> iRealObjectInformationArray;

      const TDBObjectHandleArray *iDBObjectHandleArrayPtr;
    };
    
  }
}

#endif
